#region File Description
//-----------------------------------------------------------------------------
// MainMenuScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Net;
using System.Linq;
using System.Collections.Generic;
using Microsoft.Xna.Framework.GamerServices;
using System;
using Arcadium.Screens.Menus.Sidebar;
#endregion

namespace Arcadium
{
    /// <summary>
    /// The main menu screen is the first thing displayed when the game starts up.
    /// </summary>
    class MainMenuScreen : MenuScreen
    {
        #region Initialization


        /// <summary>
        /// Constructor fills in the menu contents.
        /// </summary>
        public MainMenuScreen()
            : base("Main Menu")
        {
            // Create our menu entries.
            MenuEntry storyModeMenuEntry = new MenuEntry("Story Mode");
            MenuEntry freePlayMenuEntry = new MenuEntry(Resources.FreePlay);
            MenuEntry achievementsMenuEntry = new MenuEntry(Resources.Achievements);
            MenuEntry optionsMenuEntry = new MenuEntry(Resources.Options);
            MenuEntry exitMenuEntry = new MenuEntry(Resources.Exit);

            // Hook up menu event handlers.
            storyModeMenuEntry.Selected += StoryModeMenuEntrySelected;
            freePlayMenuEntry.Selected += FreePlayMenuEntrySelected;
            achievementsMenuEntry.Selected += AchievementsMenuEntrySelected;
            optionsMenuEntry.Selected += OptionsMenuEntrySelected;
            exitMenuEntry.Selected += ExitEntrySelected;

            // Add entries to the menu.
            MenuEntries.Add(storyModeMenuEntry);
            MenuEntries.Add(freePlayMenuEntry);
            MenuEntries.Add(achievementsMenuEntry);
            MenuEntries.Add(optionsMenuEntry);
            MenuEntries.Add(exitMenuEntry);
        }

        #endregion

        #region Handle Input


        /// <summary>
        /// Event handler for when the Story mode game menu entry is selected.
        /// </summary>
        void StoryModeMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {

        }

        /// <summary>
        /// 
        /// </summary>
        void FreePlayMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            MenuSidebar menuSidebar = ScreenManager.MenuSidebar;
            if (menuSidebar != null && menuSidebar.IsLoaded)
            {
                GameSessionProperties.SetMap(menuSidebar.NetworkSession.SessionProperties, 
                    GameSessionProperties.MapType.ConstructionYard);
                menuSidebar.NetworkSession.StartGame();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        void AchievementsMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            // ScreenManager.AddScreen(new AchievementMenu(), e.PlayerIndex);
        }

        /// <summary>
        /// Event handler for when the Options menu entry is selected.
        /// </summary>
        void OptionsMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            ScreenManager.AddScreen(new OptionsMenuScreen(), e.PlayerIndex);
        }


        /// <summary>
        /// Event handler for when the Options menu entry is selected.
        /// </summary>
        void ExitEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            const string message = "Exit Main Menu (GAME)?";

            MessageBoxScreen confirmExitMessageBox = new MessageBoxScreen(message);

            confirmExitMessageBox.Accepted += ConfirmExitMessageBoxAccepted;

            ScreenManager.AddScreen(confirmExitMessageBox, e.PlayerIndex);
        }

        /// <summary>
        /// Event handler for when the user selects ok on the "are you sure
        /// you want to exit" message box.
        /// </summary>
        void ConfirmExitMessageBoxAccepted(object sender, PlayerIndexEventArgs e)
        {
            ScreenManager.Game.Exit();
        }

        /// <summary>
        /// Disposes the menu sidebar and return to activationscreen.
        /// </summary>
        /// <param name="playerIndex"></param>
        protected override void OnCancel(PlayerIndex playerIndex)
        {
            if (ScreenManager.MenuSidebar != null)
                ScreenManager.MenuSidebar.ExitSession();
        }

        #endregion

    }
}
